﻿using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using SUMO.MediaBrowser.Foundation;
using SUMO.MediaBrowser.ViewModel;
using USTF.Media.MediaService;
using USTF.Media.MediaServiceConsumer.USTFMediaServiceProxy;

namespace SUMO.MediaBrowser.Controls
{
    public class MediaTreeView : TreeView
    {


        //public event TreeNodeLoadedEventHandler TreeNodeLoaded;

        //protected virtual void OnTreeNodeLoaded(TreeNodeLoadedEventArgs e)
        //{
        //    if (TreeNodeLoaded != null)
        //    {
        //        // Invokes the delegates. 
        //        TreeNodeLoaded(this, e);
        //    }
        //}


        public MediaTreeView()
            : base()
        {

            var rootNode = new MediaTreeViewItem( new HierarchicalMediaItem(new MediaItem() { ID = -1 }, false));

            this.Items.Add(rootNode);
           // this.MouseLeftButtonUp += new MouseButtonEventHandler(OnMouseUp);

        }



        public void NodeLoaded(object sender, TreeNodeLoadedEventArgs e)
        {
            //OnTreeNodeLoaded(e);
        }

        public void refresh()
        {

            this.Items.Clear();

            this.Items.Add(new MediaTreeViewItem());

        }


        protected virtual void OnMouseUp(object sender, MouseEventArgs e)
        {
            //MediaTreeViewItem i = (MediaTreeViewItem)this.SelectedItem;
            //if (i.MediaItems == null || i.MediaItems.Count == 0)
            //{
            //    i.Items.Add(new LoadingTreeViewItem());
            //    i.readNodes();
            //}
        }

    }



    public class LoadingTreeViewItem : TreeViewItem
    {
        public LoadingTreeViewItem()
            : base()
        {
            this.Header = "Loading...";
        }
    }

    public class TreeNodeLoadedEventArgs : EventArgs
    {
        public MediaTreeViewItem TreeViewItem
        {
            get;
            set;
        }

        public TreeNodeLoadedEventArgs(MediaTreeViewItem t)
            : base()
        {
            TreeViewItem = t;
        }
    }

  //  public delegate void TreeNodeLoadedEventHandler(object sender, TreeNodeLoadedEventArgs e);
}
